//
// Created by qiangqiangj on 2019/10/12.
//

#include "url.h"
#include <stdlib.h>

static inline void free_unless_null(void *);

struct URL *url_new() {
    return (struct URL *) calloc(1, sizeof(struct URL));
}

void url_free(struct URL *self) {
    free_unless_null(self->protocol);
    free_unless_null(self->host);
    free_unless_null(self->port);
    free_unless_null(self->path);
    free(self);
}

static inline void free_unless_null(void *p) {
    if (p) {
        free(p);
    }
}


